
const Mock = require('mockjs');
const userList = [
  { id: 1, username: 'admin', roles: [], menu: [], password: '123456', token: 'admin' },
  { id: 2, username: 'user', roles: [], menu: [], password: '123456', token: 'user' },
];

module.exports = [{
  url: '/login',
  type: 'post',
  response: (req) => {
    let { username, password } = req.body;
    let userinfo = userList.find(e => e.username === username && e.password == password);
    if (userinfo) {
      return {
        msg: '',
        code: 200,
        data: {
          ...userinfo,
          nickName: '@last', //随机昵称
          phone: /^1[34578]\d{9}$/,//随机电话号码
          'age|11-99': 1,//年龄
          address: '@county(true)',//随机地址
          email: '@email',//随机邮箱
          isMale: '@boolean',//随机性别
          createTime: '@datetime',//创建时间
          avatar() {
            //用户头像
            return Mock.Random.image('100×100', Mock.Random.color(), '#757575', 'png', this.nickName)
          }
        }
      }
    } else {
      return { code: 400, msg: '用户名或密码错误' }
    }
  }
}, {
  url: '/logout',
  type: 'get',
  response: { code: 200 }
}
];
